﻿using CommandSystem;
using System;

namespace ServerQuery
{
    [CommandHandler(typeof(RemoteAdminCommandHandler))]
    public sealed class SqCommand : ParentCommand
    {
        public SqCommand() => LoadGeneratedCommands();
        public override string Command => "sq";

        public override string[] Aliases => null;

        public override string Description => "服务器RCON插件控制系统";

        public override void LoadGeneratedCommands()
        {
            this.RegisterCommand(new RefreshJson());
            this.RegisterCommand(new Reset());
        }

        protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender,
            out string response)
        {
            response = "用法：" +
                       "sq refreshjson - 刷新服务器json列表\n" +
                       "sq reset - 重置连接";
            return false;
        }
    }

    public class RefreshJson : ICommand
    {
        public string Command => "refreshjson";

        public string[] Aliases => null;

        public string Description => "";

        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            ServerQueryPlugin.instance.RegisterOtherServer();
            response = "已刷新Json列表！";
            return true;
        }
    }

    public class Reset : ICommand
    {
        public string Command => "reset";

        public string[] Aliases => null;

        public string Description => "";

        public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
        {
            SocketData.Awake(false);
            SocketData.Awake();
            response = "已尝试重新监听socket";
            return true;
        }
    }
}